package com.brower.project

import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.EditText
import androidx.databinding.BindingAdapter

fun EditText.afterTextChanged(afterTextChanged: (String) -> Unit) {
    this.addTextChangedListener(object : TextWatcher {
        override fun afterTextChanged(editable: Editable?) {
            afterTextChanged.invoke(editable.toString())
        }

        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}

        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
    })
}


@BindingAdapter("bindVis")
fun View.bindVis(vis: Boolean?) {
    visibility = if (vis == true) View.VISIBLE else View.GONE
}

@BindingAdapter("bindAfterChanged")
fun EditText.bindAfterChanged(afterTextChanged: (String) -> Unit) {
    afterTextChanged(afterTextChanged)
}

